//
//  NewsCell.m
//  WY163News
//
//  Created by rong on 15/7/15.
//  Copyright (c) 2015年 rong. All rights reserved.
//

#import "NewsCell.h"
#import "News.h"
#import <UIImageView+AFNetworking.h>

@interface NewsCell ()

@property (weak, nonatomic) IBOutlet UIImageView *picView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *digestLabel;

@property (weak, nonatomic) IBOutlet UILabel *replyLabel;


@property (strong, nonatomic) IBOutletCollection(UIImageView) NSArray *extraPicViews;


@end


@implementation NewsCell

- (void)awakeFromNib {
    // Initialization code
    
     self.digestLabel.preferredMaxLayoutWidth = [UIScreen mainScreen].bounds.size.width - CGRectGetMaxX(self.picView.frame) - 16; //  self.digestLabel.frame.origin.x
}


+ (NSString *)getCellIdentifier:(News *)new {

    if (new.imgextra.count == 2){
        return @"MutiPicNewsCell";
    }
    
    return @"NewsCell";
}

- (void)setNews:(News *)news {

    _news = news;
    
    self.titleLabel.text = news.title;
    
    self.digestLabel.text = news.digest;
    
    self.replyLabel.text = [NSString stringWithFormat:@"%d", news.replyCount];
    
    
    [self.picView setImageWithURL:[NSURL URLWithString:news.imgsrc]];
    
    
    if (self.news.imgextra.count == 2) {
        
        int index = 0;
        
        for (UIImageView * vc in self.extraPicViews) {
            
            // !!!!  是一个字典数组，需要通过key 取出里面的数据
            [vc setImageWithURL:[NSURL URLWithString:news.imgextra[index][@"imgsrc"]]];
            
            index++;
        }
    }
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
